import com.mchange.v2.c3p0.ComboPooledDataSource;
import com.mysql.fabric.ShardTable;
import jdk.internal.dynalink.beans.StaticClass;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;
import org.apache.commons.dbutils.handlers.ArrayListHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class DButil {
    public static List getData() throws SQLException {
        ComboPooledDataSource comboPooledDataSource = new ComboPooledDataSource();
        QueryRunner que = new QueryRunner(comboPooledDataSource);
        List<Object[]> result = que.query("select username from user", new ArrayListHandler());
        List list = new ArrayList();
        for (Object[] res : result) {
            list.add(res[0]);
        }
        comboPooledDataSource.close();
        return list;
    }
    public static void inputData(String username,String password) throws SQLException {
        ComboPooledDataSource comboPooledDataSource = new ComboPooledDataSource();
        QueryRunner que = new QueryRunner(comboPooledDataSource);
        String []data={username,password};
        que.update("insert into user values(?,?)", data);
        comboPooledDataSource.close();

    }

}
